<script>
    const arr = [2,4,1,5,3];
    // 1.冒泡排序  每次相邻的元素进行比较，内圈是自己进行比较
    for(var i=0;i<arr.length;i++){
        for (var j = 0; j < arr.length-1-i; j++) {
            if(arr[j]>arr[j+1]){
                let tmp = arr[j];
                arr[j]=arr[j+1];
                arr[j+1]=tmp;
            }  
        }
    }
    console.log(arr);
    // 2.选择排序
    const array = [9,7,6,8,5]
    for (let i = 0; i < array.length; i++) {
        for (let j = 0; j < array.length-i-1; j++) {
            if(array[j]>array[array.length-i-1]){
                [array[j],array[array.length-i-1]]=[array[array.length-i-1],array[j]]
            }
            
        }
        
    }
    console.log(array);

</script>